<template>
  <div>
    <div>
      <el-upload
        ref="upload" 
        action=""
        :http-request="fileUploadFn" 
      > 
        <el-button slot="trigger" size="small" type="primary">选取文件</el-button> 
      </el-upload>

      <el-button size="small" type="primary" @click="test">test({{uploadPercentage}}%)</el-button>

      <el-button size="small" type="primary" @click="downloadBig">downloadBig</el-button>

      <el-button size="small" type="primary" @click="downloadById">downloadById</el-button>
    </div>
    
  </div>
</template>
<script>
import {normalUpload, bigFileUpload, downloadFile} from '@/helper/updownload'
import {FILE_UPLOAD, FILE_DOWNLOAD, UPLOAD_BIG_FILE, UPLOAD_BIG_FILE_FINISH, DOWNLOAD_BIG_FILE, fileDownloadById} from '$my/code/api/file'
import {SERVER_HOST} from '@/constant'
import {download} from '$ui/utils/download'
// import ajax from '$ui/utils/ajax' 
import axios from 'axios'
export default {
  components: {},
  props: {
  },
  data() {
    return {
      uploadPercentage: 0
      // uploadPath: FILE_UPLOAD
    }
  },
  computed: {
  },
  watch: {
    uploadPercentage(val) {
      console.log(val)
    }
  },
  methods: {
    // getOptionsMap,
    fileUploadFn(target) { 
      
      normalUpload(target.file, FILE_UPLOAD)
    },
    test() {
      downloadFile.apply(this, ['test.txt', FILE_DOWNLOAD]).then((res) => {
        console.log(res)
      }).catch(() => {
        this.$message.warning('没有对应文件')
      })
    },
    bigDataUpload(header) {
      console.log(arguments)
      bigFileUpload.apply(this, [header.file, UPLOAD_BIG_FILE, UPLOAD_BIG_FILE_FINISH, 'uploadPercentage', 1]) 
    },
    downloadBig() {
      return axios({
        url: DOWNLOAD_BIG_FILE,
        method: 'post',
        headers: {
          authorization: this.$access.get().token || ''
          // range: 0
          // 'Content-Range': 6
          // range: 6
        },
        data: {name: '1603514751243SILK060.avi'}
        // responseType: 'blob'
      }).then((res) => {

      })
    },
    downloadById() {
      fileDownloadById({id: 'FS-310H5_Func.pdf@\\uploads\\FS-310H5_Func_1604560560429.pdf'}).then((res) => {
        console.log(res.url)
        download(SERVER_HOST + res.url)
      })
    }
     
  },
  created() {
    
  },
  mounted() {
  }
}
</script>
<style lang="scss" scoped>
</style>